layer = 2;
site = 2;
time = 2;

figure;hold on
xlim([-100 2600])
ylim([-70 60])

for ind = 0:1
    % generate binary activity of motion.
    frm = ind*7500;
    velM = -proj_meta(site).rd(layer,time).velM_smoothed(frm+1:frm+2500);
    velM_bi = velM;
    velM_bi(velM_bi > 0.001) = 1;
    velM_bi(velM_bi <= 0.001) = 0;

    % generate binary activity of visual flow.
    velP = -proj_meta(site).rd(layer,time).velP_smoothed(frm+1:frm+2500);
    velP_bi = velP;
    velP_bi(velP_bi > 0.001) = 1;
    velP_bi(velP_bi <= 0.001) = 0;

    VM_bi = vertcat(velP_bi,velM_bi);

    bl_id = 0;
    fb_id = 0;
    pb_id = 0;
    mm_id = 0;
    bl = [];
    fb = [];
    pb = [];
    mm = [];
    for frame_id = 1:size(VM_bi,2)
        if VM_bi(:,frame_id) == [1;1]
            fb_id = fb_id + 1;
            fb(fb_id) = frame_id; % frame_id of feedback
        end
        if VM_bi(:,frame_id) == [1;0]
            pb_id = pb_id + 1;
            pb(pb_id) = frame_id; % frame_id of playback
        end
        if VM_bi(:,frame_id) == [0;1]
            mm_id = mm_id + 1;
            mm(mm_id) = frame_id; % frame_id of mismatch
        end
    end

    fb_bi = zeros(1,2500)-ind*60;
    fb_bi(fb) = 50-ind*60;

    pb_bi = zeros(1,2500)-ind*60;
    pb_bi(pb) = 50-ind*60;

    mm_bi = zeros(1,2500)-ind*60;
    mm_bi(mm) = 50-ind*60;

    area(fb_bi,'linestyle','none','facecolor',[1 1 1]*0.6,'basevalue',-ind*60)
    area(pb_bi,'linestyle','none','facecolor',[0.9 1 0]*0.7,'basevalue',-ind*60)
    area(mm_bi,'linestyle','none','facecolor',[1 0.5 0]*0.9,'basevalue',-ind*60)
    
    plot(velP*1000+25-ind*60,'g')
    plot(velM*1000-ind*60,'r')
end